﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;
using System.Data.Common;

public partial class MRP_ReturnProductRepair : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void UIServer1_DBChange(object sender, Evolutility.UIServer.DatabaseEventArgs e)
    {
        if (e.Action == Evolutility.UIServer.DBAction.INSERT)
        {
            //如果报废数+入库数=退货单数，要看情况：如果是无需补货则关闭掉退货单；需要补货的就不改变状态
            //入库时还是要减少库存
            int id = e.ID;
            decimal oldQuantity = 0;
            decimal oldSignQuantity = 0;
            Dictionary<string, string> oldValues = e.OldValues;
            if (oldValues != null)
            {
                oldQuantity = decimal.Parse(MRPUtility.GetOldValueFromString("Quantity", oldValues, "0"));
                oldSignQuantity = decimal.Parse(MRPUtility.GetOldValueFromString("QuantityOfSign", oldValues, "0"));
            }
            Database db = DatabaseFactory.CreateDatabase("MRPSqlServer");
            string sqlCommand = "MRP_CheckOrderStatus";
            DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
            db.AddInParameter(dbCommand, "ItemID", DbType.Int32, id);
            db.AddInParameter(dbCommand, "oldQuantity", DbType.Decimal, oldQuantity);
            db.AddInParameter(dbCommand, "oldSignQuantity", DbType.Decimal, oldSignQuantity);

            db.ExecuteNonQuery(dbCommand);
        }
    }
}
